<?php

class User extends Controller {

        function User()
        {
                parent::Controller();
        }

        function user_page()
        {
            if($this->session->userdata('is_logged_in') !== 1)
                $this->load->view('user_view');
            else
                $$this->load->view('admin_view');

        }

        function login($name, $pass)
        {
            $data = array();

                //Validate & Prep
                $this->load->library('form_validation');
                $this->form_validation->set_rules($name, 'User Name', 'required|trim|strtolower');
                $this->form_validation->set_rules($pass, 'Password', 'required|trim');

                $result = $this->form_validation->run();

                if ($result === TRUE)
                {
                        //Check the username and password against the database
                        $this->load->model('users_model');
                        $result = $this->users_model->check_credentials($name, $pass);

                        //If they match, then add a variable to the session cookie
                        if ($result !== FALSE)
                        {
                                $this->session->set_userdata(array('user' => $result));
                        }
                        else
                                $data['error_msg'] = "The username or password was incorrect!";
                }
                else
                        $data['error_msg'] = "There was a problem with your submission!";
                

        }

        function retrieve_user($user_id)
        {
                $result = $this->db->get_where('user', array('UID' => $user_id));

                if ($result->num_rows() == 1)
                        return $result->row();
                else
                        return FALSE;
        }


}
//EOF